﻿using System.Collections.Generic;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MyCompany.WebCrawler.Repositories;
using MyCompany.WebCrawler.Tasks.Tasks;

namespace MyCompany.WebCrawler.Test.Domain.TasksFactoryTests.Given_ShowLinkFromDatabase
{
    [TestClass]
    public class When_ExecuteTheTask : Context
    {
        private string result;
        private string databaseUrl = "http://gooogle.com/ads";
        private ShowNewLinksTask task;

        public override void Arrange()
        {
            var fetcher = new Mock<WebCrawler.Domain.UiFetcher>();
            fetcher.Setup(f => f.Show(It.IsAny<string>())).Callback<string>(u => result += u);
            
            var repository = new Mock<Repository>();
            repository.Setup(r => r.Load()).Returns(new List<Url>() { new Url() { Path = databaseUrl } });

            task = new ShowNewLinksTask(fetcher.Object, repository.Object);
        }

        public override void Act()
        {
            task.Execute();
        }

        [TestMethod]
        public void Then_LinkIsShown()
        {
            result.Should().Be(databaseUrl);
        }

    }
}